<?php
namespace UserApi\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;
class SubmitwinnerApiController extends AbstractRestfulController
{
    public function getList()
    {	
		
    }
    public function get($imeinumber)
    {
		header('Access-Control-Allow-Origin: *');		
		
    }
    public function create($data)
    {
		header('Access-Control-Allow-Origin: *');	
		$winnerDetailesTable=$this->getServiceLocator()->get('Models\Model\WinnerdetailsFactory');
			global $wonGameSubject;
			global $wonGameMessage;	
			$username=$data['name'];
			$userphone=$data['phone'];
			$useremail=$data['email'];	
			$saveContactDetailes=$winnerDetailesTable->saveContactDetailes($data);
			$wonGameMessage = str_replace("<FULLNAME>","$username", $wonGameMessage);
			$wonGameSubject = str_replace("<FULLNAME>","$username", $wonGameSubject);
			$wonGameMessage = str_replace("<EMAIL>","$useremail", $wonGameMessage);
			$wonGameMessage = str_replace("<PHONENUMBER>","$userphone", $wonGameMessage);
			$to="sacharya@cyclonellc.net,satwin123@gmail.com";	
			if(sendMail($to,$wonGameSubject,$wonGameMessage)){
				$result = new JsonModel(array(
					'status'		=>	'success',
					'userid'		=>	json_encode($saveContactDetailes),
					'value'			=>	1,
				));	
			}else{
				$result = new JsonModel(array(					
					'status' 	=> 'fail',
					'value' 	=> '0',
				));	
			}
			return $result;
	}
    public function update($imeinumber, $data)
    {
		header('Access-Control-Allow-Origin: *');	
		$userDetailesTable=$this->getServiceLocator()->get('Models\Model\UserdetailesFactory');
		
		$checkingImeiNumber = $userDetailesTable->checkImeiNumber($imeinumber)->toarray();
		
		if(count($checkingImeiNumber)!=0){
			return new JsonModel(array(
				'checkStatus' 		=> json_encode($checkingImeiNumber),
				'value' 			=> 2,
			));	
		}else{
			$userDetailes=$userDetailesTable->registerDetailes($data);
			if($userDetailes!=0){
				return new JsonModel(array(
					'status'		=>	'success',
					'user_id'		=>	$userDetailes,
					'value'			=>	1,
				));	
			}else{
				return new JsonModel(array(
					'status'	=>	'fail',
					'value'		=>   0,
				));			
			}
		}
	
    }
    public function delete($id)
    {
       
    }
}